package gov.nist.ssd.swqb.core.search;

import com.hp.hpl.jena.rdf.model.Model;

import gov.nist.ssd.swqb.core.search.AbstractSearch.ExactMatchText;

class AnyNodeExactSearch extends MergedSearch {


	
	public AnyNodeExactSearch(ExactMatchText emt,
														Model model,
														int requestsSize) {

		super(
				new LitteralExactSearch(emt, model, requestsSize),
				new AnonExactSearch(emt, model, requestsSize),
		/*
		 * This part is really twisted but super class constructor has to be the
		 * first instruction...
		 * 
		 * This piece of code intend to create an ExactUriNodeSearch iff the search
		 * text is a valid node search. If it starts with a '-' or a digit creating
		 * an ExactUriNodeSearch would crash at query time.
		 */
		 (
				(firstChar(emt) == '-' || (firstChar(emt) >= '0' && firstChar(emt) <= '9'))
				  ? null
				  : new UriNodeExactSearch(emt, model, requestsSize)
		  )
				);
		
	}
	
	private static char firstChar(ExactMatchText emt) {
		return emt.toString().charAt(0);
	}
}
